# -*- coding: utf-8 -*-
### required - do no delete
def user(): return dict(form=auth())
def download(): return response.download(request,db)
def call():
    session.forget()
    return service()
### end requires

@auth.requires_login()
def addimg():
    form = SQLFORM(db.app_items,
        fields = ['img_name', 'image', 'invite_message', 'redirect'],
        labels =  {'img_name': 'Image Name', \
                'image':'Upload image'},
        col3 = {'image':SPAN('Maximum image size: 1MB, please use small \
                picture to keep app fast.'),})
    if form.accepts(request.vars, session):
        response.flash = 'image uploaded'
    elif form.errors:
        response.flash = 'please check the errors'
    else:
        response.flash = 'please fill in something'
    return dict(form=form)

@auth.requires_login()
def del_img():
    try:
        db(db.app_items.id == int(request.vars.get("id"))).delete()
        db.commit()
    except:
        return 'delete image failed!'
    else:
        return 'delete succeed!'

@auth.requires_login()
def listimg():
    images = db().select(db.app_items.ALL, orderby = db.app_items.id)
    return dict(images=images)

def farmville():
    return dict()

def error():
    return dict()
